package com.bdqn.tour.service.impl;



import com.bdqn.tour.dao.HzyTravelersDao;
import com.bdqn.tour.dao.impl.HzyTravelersDaoImpl;
import com.bdqn.tour.pojo.HzyTraveler_documents;
import com.bdqn.tour.pojo.HzyTravelers;
import com.bdqn.tour.service.HzyTravelersService;

import java.util.List;

public class HzyTravelersServiceImpl implements HzyTravelersService {
    HzyTravelersDao HzyTravelersDao = new HzyTravelersDaoImpl();

    @Override
    public int addTraveler(HzyTravelers travelers) {
        // 添加旅客信息并获取生成的ID
        int generatedId = HzyTravelersDao.addTraveler(travelers);

        // 只有在成功插入旅客信息并且有证件信息时才添加证件
        if (generatedId > 0 && travelers.getDocuments() != null) {
            for (HzyTraveler_documents document : travelers.getDocuments()) {
                document.setTraveler_id(generatedId);
                HzyTravelersDao.addTraveler_documents(document);
            }
        }
        return generatedId;
    }

    @Override
    public List<HzyTravelers> getTravelersList(String searchName) {
        return HzyTravelersDao.getTravelersList(searchName);
    }

    @Override
    public boolean deleteTraveler(int id) {
        return HzyTravelersDao.deleteTraveler(id);
    }

    @Override
    public boolean setDefaultTraveler(int id) {
        return HzyTravelersDao.setDefaultTraveler(id);
    }

    @Override
    public HzyTravelers getTravelerById(int id) {
        return HzyTravelersDao.getTravelerById(id);
    }

    @Override
    public boolean updateTraveler(HzyTravelers travelers) {
        return HzyTravelersDao.updateTraveler(travelers);
    }

    @Override
    public boolean deleteAllDocuments(int travelerId) {
        return HzyTravelersDao.deleteAllDocuments(travelerId);
    }
}
